-- TransAttrEquipRender

local TransAttrOfEquipRender = app.mvc.createListViewCell(...)

function TransAttrOfEquipRender.create(node)
    local sprite = TransAttrOfEquipRender.extend(node or cc.CSLoader:createNode(Res.NewBagNode))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init()
    return sprite
end

function TransAttrOfEquipRender:init(data)
    self.super.init(self, data)
    self:setContentSize(self._ui.Panel:getContentSize())
    self:refresh()

    self._ui["Panel"]:setTouchEnabled(true)
    self._ui["Panel"]:addTouchEventListener(function(sender,eventType)
        if eventType == ccui.TouchEventType.ended and self._cellModel and self._cellModel:getIndex() ~= self._cellModel:getFoucsIndex() then
            self:dispatchCellEvent("click", self._cellModel)
        end
    end)
end

function TransAttrOfEquipRender:refresh()
    if self._data then
        self:refreshBrightStatus()
        local data = self._data
        self._ui["Panel/grade"]:loadTexture(data:getIconBg())
        self._ui["Panel/icon"]:loadTexture(data:getIcon())
        self._ui["Panel/equipped"]:setVisible(UD:isEquiped(data))
        self._ui["Panel/mask_red"]:setVisible(false)
        self._ui["Panel/shift"]:setVisible(false)
        self._ui["Panel/cue"]:setVisible(false)
        self._ui["Panel/img_ContinueFlag"]:setVisible(false)
        self._ui["Panel/Panel_gem"]:setVisible(false)
        self._ui["Panel/Panel_wing"]:setVisible(false)
        self._ui["Panel/Panel_lock"]:setVisible(false)
        self._ui["Panel/Panel_num"]:setVisible(false)
        self._ui["Panel/num"]:setVisible(false)
    end
end

function TransAttrOfEquipRender:refreshBrightStatus()
    if self._cellModel then
        self._ui["Panel/selected"]:setVisible(self._cellModel:getIndex() == self._cellModel:getFoucsIndex())
    else
        self._ui["Panel/selected"]:setVisible(false)
    end
end

function TransAttrOfEquipRender:onFoucsIndexChange(foucsIndex)
    self:refreshBrightStatus()
end

return TransAttrOfEquipRender